package com.system.controller;

import com.system.pojo.Address;
import com.system.service.AddressService;
import com.system.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yjymm
 * @date 2019-12-13 21:45
 */
@Controller
@ResponseBody
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @RequestMapping("/insert")
    public ResultVo<Address> insert(Address address){
        ResultVo<Address> resultVo = null;
        try {
            resultVo = addressService.insert(address);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("添加收获地址失败");
        }finally {
            return resultVo;
        }
    }

    @RequestMapping("/detail/{addressId}")
    public ResultVo<Address> detail(@PathVariable Integer addressId){
        ResultVo<Address> resultVo = new ResultVo<>();
        try {
            resultVo = addressService.detail(addressId);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("更新地址失败");
        }finally {
            return  resultVo;
        }
    }

    @RequestMapping("/update")
    public ResultVo<Address> update(Address address){
        ResultVo<Address> resultVo = new ResultVo<>();
        try {
            resultVo = addressService.update(address);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("更新地址失败");
        }finally {
            return  resultVo;
        }
    }
    
    
    @RequestMapping("/delete/{addressId}/{clientId}")
    public ResultVo<Address> delete(@PathVariable Integer addressId,@PathVariable Integer clientId){
        ResultVo<Address> resultVo = new ResultVo<>();
        try {
            resultVo = addressService.delete(addressId,clientId);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("更新地址失败");
        }finally {
            return  resultVo;
        }
    }
    
    


}
